// pages/loupan/list.js
var api = require('../../utils/api.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    anlilist:[],
    detail:[],
    page: 1,
    listcount: 1,
    count:8,
    loupanlist:[],
    citys:[],
    index:-1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    this.loadloupan(1, this.data.count);
    this.loadanli();
    this.loaddetail(options.id);
    this.dialog = this.selectComponent("#mydialog");
    this.loadcitys();
  },
  callphonenum() {
    wx.makePhoneCall({
      phoneNumber: '4001529288'
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
 
  //加载相关案例
  loadanli() {
    api.get({
      url: '/portal/lists/getCategoryPostLists',
      data: {
        category_id: 2,
        field: 'post.id,post.post_title,post.more',
        limit:3,
        order: '-post.id'
      },
      success: data => {
        if (data.code == '1') {
          this.setData({
            anlilist: data.data.list
          })
        }
      }
    })
  },
  //加载热装楼盘
  loadloupan(page,count) {
    api.get({
      url: '/portal/lists/getCategoryPostLists',
      data: {
        category_id: 1,
        field: 'post.id,post.post_title,post.more',
        page: page + ',' + count,
        order: '-post.id'
      },
      success: data => {
        if (data.code == '1') {
          this.setData({
            loupanlist: this.data.loupanlist.concat(data.data.list),
            page: page,
            listcount: data.data.list.length
          })
        }
      }
    })
  },
  loadmore(e) {
    let page = this.data.page + 1;
    this.loadloupan(page, this.data.count);
  },

  loaddetail(id){
    api.get({
      url: '/portal/articles/'+id,
      success:data=>{
        if (data.code == '1') {
          this.setData({
            detail: data.data
          })
        }
      }
    })
  },

  formSubmit(e) {
    //提交表单数据
    api.post({
      url: '/portal/diyform/insert',
      data: e.detail.value,
      success: data => {
        if (data.code == "1") {
          wx.showToast({ title: '报名成功', icon: 'success' })
          this.dialog.hideModal();
        }
        if (data.code == "0") {
          wx.showToast({ title: data.msg, icon: 'none' })
        }
      }
    })
  },

  yuyuefunc(e){
    this.dialog.showModal();
    this.dialog.setparam(this.data.citys);
  },
  _hideModal() {
    this.dialog.hideModal();
  },
  loadcitys(){
    api.get({
      url: 'home/attribute/11',
      success: data => {
        if (data.code == 1) {
          this.setData({
            citys: data.data[0].items
          })
        }
      }
    });
  },
  bindCitysChange(e) {
    this.setData({
      index: e.detail.value
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})